package com.roc.service.merinfo;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.roc.bean.MerinfoChangeBean;
import com.roc.bean.MerinfoChangeSearchVo;
import com.roc.dao.DaoException;
import com.roc.dao.IMerchantDao;
import com.roc.dao.ISQLBaseDao;
import com.roc.dao.merinfo.MerinfoChangeCheckDao;
import com.roc.newPage.IPageDao;
import com.roc.pojo.AuditingItem;
import com.roc.pojo.MerinfoChange;
import com.roc.pojo.MerinfoStatusChange;
import com.roc.pojo.Operators;
import com.roc.pojo.TblEditTermInf;
import com.roc.pojo.TblEditTermRiskCfg;
import com.roc.pojo.TblMchtBankAccount;
import com.roc.pojo.TblMchtBizDeal;
import com.roc.pojo.TblMchtBizFee;
import com.roc.pojo.TblMchtInf;
import com.roc.pojo.TblMchtPicture;
import com.roc.pojo.TblTermInf;
import com.roc.pojo.TblTermInfId;
import com.roc.pojo.TblTermRiskCfg;
import com.roc.pojo.TblTermRiskCfgId;
import com.roc.service.ServiceException;
import com.roc.util.Constance;
import com.roc.util.constant.AuditingType;
import com.roc.util.constant.ConfigMerinfoUtil;
import com.roc.util.constant.ConfigProperties;
import com.roc.util.constant.MerinfoStatus;
import com.roc.util.constant.SysLogType;
import com.roc.util.httpUtil.HttpClientUtil;

/**
 * 商户复审service
 * @author jdd
 *
 */

@Service("merinfoChangeCheckService")
@Transactional(rollbackFor = { ServiceException.class })
public class MerinfoChangeCheckServiceImpl implements MerinfoChangeCheckService{

	static Logger logger = LogManager.getLogger(MerinfoChangeCheckServiceImpl.class);
	@Autowired
	private MerinfoChangeCheckDao merinfoChangeCheckDao;
	
	@Autowired
	private IMerchantDao merchantDao;
	@Autowired
	private IPageDao  pageDao;
	@Autowired
	ISQLBaseDao sqlBaseDao;
	/**
	 * 商户变更信息查询
	 * @Title: queryTerChangeByMid
	 * @Description:TODO(...)
	 * @param mid
	 * @return
	 * @throws DaoException
	 * @author jdd
	 * @date: 2016年12月26日 下午4:22:54
	 *
	 */
	

	@Override
	public MerinfoChangeBean queryMerinfoChangeById(String id) throws ServiceException {
		// TODO Auto-generated method stub
		MerinfoChangeBean merinfo = null;
		List<Object> params=new ArrayList<Object>();
		try {
			StringBuffer sql=new StringBuffer("select TM.ID ,TM.MID   ,TM.NAME_BUSI   ,TM.CONTACT_PHONE_NO  ,"
					+ " TM.BANK_ACCOUNT_NAME    ,TM.BANK_ACCOUNT  ,TM.OPEN_BANK   ,TM.BANK_CODE ,  "
					+ " TT.TERM_TP  ,TT.TMNL_INTYPE,TT.TMNL_MONEY ,TT.INSTALLLOCATION ,  "
					+ " TF.MCHT_FEE_MD ,TF.MCHT_FEE_PERCENT   ,TF.MCHT_FEE_PCT_MAX,  "
					+ "  TD.PROD_CD ,  TD.TRANS_CD , TI.STATUS,  "
					+ " TM.URL1 , TM.URL2 , TM.URL3 , TM.URL4 , TM.URL5  ,   "
					+ " TM.URL6 , TM.URL7 , TM.URL8 , TM.URL9 , TM.URL10 ,   "
					+ " TM.ACCOUNT_NO , TM.DEAL_CODE , TM.CONTACT_NAME , TM.PUB_OR_PRI ,  "
					+ "  TM.DVP_BY , TM.STLM_WAY_DESC ,TM.CERTIF "
					+ "   FROM       T_MERINFO_CHANGE    TM   "
					+ " LEFT JOIN  TBL_EDIT_TERM_INF      TT   ON TM.MID = TT.MCHT_CD  "
					+ " LEFT JOIN  TBL_EDIT_MCHT_BIZ_FEE  TF   ON TM.MID = TF.MCHT_CD   "
					+ "  LEFT JOIN  TBL_EDIT_MCHT_BIZ_DEAL TD   ON TM.MID = TD.MCHT_CD  "
					+ " LEFT JOIN   TBL_EDIT_MCHT_INF     TI   ON TM.MID = TI.MCHT_CD   "
					+ "  WHERE TM.mid=? and TM.STATUS='L'    " );
			
			params.add(id);
			List list = merinfoChangeCheckDao.queryBySqlToVo(sql.toString(),params.toArray());
		
			if(!list.isEmpty())
			{
				Object[] obj=(Object[]) list.get(0);
				merinfo = new MerinfoChangeBean();
				merinfo.setId(Long.parseLong(Constance.Null2EmptyTrim(obj[0])));
				merinfo.setMid(Constance.Null2EmptyTrim(obj[1]));
				merinfo.setNameBusi(Constance.Null2EmptyTrim(obj[2]));
				merinfo.setContactPhoneNo(Constance.Null2EmptyTrim(obj[3]));
				merinfo.setBankAccountName(Constance.Null2EmptyTrim(obj[4]));
				merinfo.setBankAccount(Constance.Null2EmptyTrim(obj[5]));
				merinfo.setOpenBank(Constance.Null2EmptyTrim(obj[6]));
				merinfo.setBankCode(Constance.Null2EmptyTrim(obj[7]));
				/*merinfo.setTremTp(Constance.Null2EmptyTrim(obj[8]));
				merinfo.setTmnlIntype(Constance.Null2EmptyTrim(obj[9]));
				if(!"".equals(Constance.Null2EmptyTrim(obj[10]))){
				
				merinfo.setTmnlMoney(Double.parseDouble(Constance.Null2EmptyTrim(obj[10])));
				}
				merinfo.setInstallLocation(Constance.Null2EmptyTrim(obj[11]));*/
				merinfo.setMchtFeeMd(Constance.Null2EmptyTrim(obj[12]));
				if(!"".equals(Constance.Null2EmptyTrim(obj[13]))){	
				merinfo.setMchtFeePercent(Double.parseDouble(Constance.Null2EmptyTrim(obj[13])));
				}
				if(!"".equals(Constance.Null2EmptyTrim(obj[14]))){	
				merinfo.setMchtFeePctMax(Double.parseDouble(Constance.Null2EmptyTrim(obj[14])));
				}
				merinfo.setProdCd(Constance.Null2EmptyTrim(obj[15]));
				merinfo.setTransCd(Constance.Null2EmptyTrim(obj[16]));
				merinfo.setStatus1(Constance.Null2EmptyTrim(obj[17]));

				merinfo.setUrl1(Constance.Null2EmptyTrim(obj[18]));
				merinfo.setUrl2(Constance.Null2EmptyTrim(obj[19]));
				merinfo.setUrl3(Constance.Null2EmptyTrim(obj[20]));
				merinfo.setUrl4(Constance.Null2EmptyTrim(obj[21]));
				merinfo.setUrl5(Constance.Null2EmptyTrim(obj[22]));
				merinfo.setUrl6(Constance.Null2EmptyTrim(obj[23]));
				merinfo.setUrl7(Constance.Null2EmptyTrim(obj[24]));
				merinfo.setUrl8(Constance.Null2EmptyTrim(obj[25]));
				merinfo.setUrl9(Constance.Null2EmptyTrim(obj[26]));
				merinfo.setUrl10(Constance.Null2EmptyTrim(obj[27]));
				merinfo.setAccountNo(Constance.Null2EmptyTrim(obj[28]));
				merinfo.setDealCode(Constance.Null2EmptyTrim(obj[29]));
				merinfo.setContactName(Constance.Null2EmptyTrim(obj[30]));
				merinfo.setPubOrPri(Constance.Null2EmptyTrim(obj[31]));
				merinfo.setDvpBy(Constance.Null2EmptyTrim(obj[32]));
				merinfo.setStlmWayDesc(Constance.Null2EmptyTrim(obj[33]));
				merinfo.setCertif(Constance.Null2EmptyTrim(obj[34]));
				List<Object> list_t1=new ArrayList<Object>();
				StringBuffer sql_t1=new StringBuffer();
				sql_t1.append("select TF.MCHT_FEE_PERCENT,TF.sub_biz_cd from TBL_EDIT_MCHT_BIZ_FEE TF where TF.MCHT_CD=? and ( TF.prod_cd=? or TF.prod_cd=?)   ");
				list_t1.add(merinfo.getMid());
				list_t1.add(ConfigMerinfoUtil.T1_FUNCTION);
				list_t1.add(ConfigMerinfoUtil.T0_FUNCTION);
				List data_t1 = merinfoChangeCheckDao.queryBySqlToVo(sql_t1.toString(),list_t1.toArray());
				Map<String, String> map_t1=new HashMap<String, String>();
				Map<String, String> map_t0=new HashMap<String, String>();
				for (Object o : data_t1) {
					Object[] os=(Object[]) o;
					if("0001000".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_t1.put("t1_j", Constance.Null2EmptyTrim(os[0]));
					}else if("0001001".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_t1.put("t1_d", Constance.Null2EmptyTrim(os[0]));
					}else if("0002000".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_t0.put("t0_j", Constance.Null2EmptyTrim(os[0]));
					}else if("0002001".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_t0.put("t0_d", Constance.Null2EmptyTrim(os[0]));
					}
				}
				merinfo.setT1(map_t1);
				merinfo.setT0(map_t0);
				
				List<Object> list_tf1=new ArrayList<Object>();
				StringBuffer sql_tf1=new StringBuffer();
				sql_tf1.append("select TF.MCHT_FEE_PCT_MAX,TF.sub_biz_cd,tf.mcht_a_fee_percent from TBL_EDIT_MCHT_BIZ_FEE TF where TF.MCHT_CD=? and ( TF.prod_cd=? or TF.prod_cd=?)   ");
				list_tf1.add(merinfo.getMid());
				list_tf1.add(ConfigMerinfoUtil.T1_FUNCTION);
				list_tf1.add(ConfigMerinfoUtil.T0_FUNCTION);
				List data_tf1 = merinfoChangeCheckDao.queryBySqlToVo(sql_tf1.toString(),list_tf1.toArray());
				Map<String, String> map_tf1=new HashMap<String, String>();
				Map<String, String> map_tf0=new HashMap<String, String>();
				for (Object o : data_tf1) {
					Object[] os=(Object[]) o;
					if("0001000".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_tf1.put("tf1_j", Constance.Null2EmptyTrim(os[0]));
					}else if("0001001".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_tf1.put("tf1_d", Constance.Null2EmptyTrim(os[0]));
					}else if("0002000".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_tf0.put("tf0_j", Constance.Null2EmptyTrim(os[0]));
						map_tf0.put("tdf0_j", Constance.Null2EmptyTrim(os[2]));
					}else if("0002001".equals(Constance.Null2EmptyTrim(os[1])))
					{
						map_tf0.put("tf0_d", Constance.Null2EmptyTrim(os[0]));
					}
				}
				
				merinfo.setTf1(map_tf1);
				merinfo.setTf0(map_tf0);
			}
			List<Object> params1=new ArrayList<Object>();
			StringBuffer sqlTerm=new StringBuffer(" select TERM_TP, TMNL_INTYPE,TMNL_MONEY , INSTALLLOCATION   "
					+ "   FROM   TBL_EDIT_TERM_INF  "
					+ "  where MCHT_CD =? and status='10'  "  );
			params1.add(merinfo.getMid());
			List tremlist = merinfoChangeCheckDao.queryBySqlToVo(sqlTerm.toString(),params1.toArray());
			if(!tremlist.isEmpty())
			{
				List<TblEditTermInf> tbleditlist=new ArrayList<TblEditTermInf>();
				for (Object object : tremlist) {
					Object[] objs=(Object[]) object;
					TblEditTermInf tbledit=new TblEditTermInf();
					tbledit.setTermTp(Constance.Null2EmptyTrim(objs[0]));
					tbledit.setTmnlIntype(Constance.Null2EmptyTrim(objs[1]));
					if(!"".equals(Constance.Null2EmptyTrim(objs[2]))){
						
					tbledit.setTmnlMoney(Double.parseDouble(Constance.Null2EmptyTrim(objs[2].toString())));
					}
					tbledit.setInstalllocation((Constance.Null2EmptyTrim(objs[3])));
					tbleditlist.add(tbledit);
				}
				merinfo.setTblEdits(tbleditlist);
			}
			
			
		} catch (DaoException e) {
			e.printStackTrace();
			logger.error("查询商户信息变更失败", e);
			throw new ServiceException("查询商户信息变更失败");
		}
		return merinfo;
	}

	/*
	 * 
	 * @see com.roc.service.merinfo.MerinfoChangeCheckService#checkChangeShutDown(java.lang.String, com.roc.pojo.Operators)
	 *
	 * @Title: checkChangeShutDown
	 * @Description:TODO(...)
	 * @param id
	 * @param op
	 * @author jdd
	 * @date: 2016年12月25日 下午2:34:36
	 *
	 */
	@Override
	public void checkChangeShutDown(String id, Operators op,AuditingItem aud) throws ServiceException {
		// TODO Auto-generated method stub
		editSave(id, op, aud);//保存 审核表信息
		StringBuffer sql=new StringBuffer();
		List<Object> list=new ArrayList<Object>();
		sql.append(" update  t_merinfo_change set OPERATORS=?, status='N', DT_AUDITOR_TIME=?, REMARK=? where STATUS='L'  and MID=? ");
		list.add(op.getRealName());
		list.add(new Date());
		list.add(aud.getResult_detail());
		list.add(id);
		
		
		try {
			//修改变更表状态
			int i=merinfoChangeCheckDao.updateBySql(sql.toString(), list.toArray());
			if(i>0)
			{
				merchantDao.addSyslog(SysLogType.MERINFO_CHANGE_ZENGJI.getCode(),
				SysLogType.MERINFO_CHANGE_ZENGJI.getName(),op.getAccountNo(), "操作员【" + op.getAccountNo()+ "】，商户【" + id+ "】变更资料申请被拒绝！");
			}else
			{
				logger.error("商户审核终止失败:商户id="+id);
				throw new ServiceException("商户审核终止失败:商户id="+id);
			}
		// 删除终端（临时表）
        String sql_dele=" DELETE  FROM TBL_EDIT_TERM_INF WHERE MCHT_CD=? and  Status='10'  " ;
		Object[] tblInfParams={id};  
		merinfoChangeCheckDao.updateBySql(sql_dele,tblInfParams);
		//删除终端风控信息（临时表）
		String sql_cfgDelet=" DELETE  FROM TBL_EDIT_TERM_RISK_CFG WHERE MCHT_CD=?   " ;
		Object[] tblcfgParams={id}; 
        merinfoChangeCheckDao.updateBySql(sql_cfgDelet,tblcfgParams);
		//删除手续费信息（临时表）
		String sql_delet=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
		Object[] tblfeeParams={id}; 
        merinfoChangeCheckDao.updateBySql(sql_delet,tblfeeParams);
        //删除开通产品信息（临时表）
        String sql_delete=" DELETE  FROM TBL_EDIT_MCHT_BIZ_DEAL  WHERE MCHT_CD=?   " ;
		Object[] deleteParams={id};  
		merinfoChangeCheckDao.updateBySql(sql_delete,deleteParams);
        //更改领件表状态
		String r_sql="UPDATE T_CHANGE_RECEIVE T SET T.STATUS='1' WHERE T.STATUS='0' AND  T.MERNO=?";
		Object[] receiveList={id}; 
		merinfoChangeCheckDao.updateBySql(r_sql, receiveList);
		
		logger.info("------------------------商户【"+id+"】领件状态更新成功--------------------");
		logger.info("------------------------商户【"+id+"】变更审核终止完成--------------------");
			
		} catch (Exception e) {
			// TODO: handle exception
			logger.error("商户审核终止失败", e);
			throw new ServiceException("商户审核终止失败");
		}
	}
	/**
	 * 商户审核,添加审核表信息
	 * @Title: editSave
	 * @Description:TODO(...)
	 * @param id
	 * @param op
	 * @param aud
	 * @return
	 * @throws ServiceException
	 * @author jdd
	 * @date: 2016年12月25日 下午3:30:14
	 *
	 */
	@SuppressWarnings("finally")
	private AuditingItem editSave(String id, Operators op,AuditingItem aud) throws ServiceException
	{
		aud.setAudit_code(AuditingType.MERCHANT_CHANGE_AUDITING.getCode());// 审核编码
		aud.setAudit_name(AuditingType.MERCHANT_CHANGE_AUDITING.getName());// 审核名称
		aud.setObj_Audited(id); // 审核对象
		aud.setOperators(op.getAccountNo());// 审核操作员
		try {
			merchantDao.editSave(aud);
		} catch (DaoException e) {
			// TODO Auto-generated catch block
			logger.error("商户审核,添加审核表信息失败", e);
			throw new ServiceException("商户审核,添加审核表信息失败");
		}finally{
			return aud;
		}
	}
	/*
	 * 
	 * @see com.roc.service.merinfo.MerinfoChangeCheckService#checkChangePass(com.roc.pojo.MerinfoChange, com.roc.pojo.Operators, com.roc.pojo.AuditingItem)
	 *
	 * @Title: checkChangePass
	 * @Description:TODO(...)
	 * @param merinfoChange
	 * @param op
	 * @param auditing
	 * @author jdd
	 * @date: 2016年12月25日 下午3:36:50
	 *
	 */
	@Override
	public void checkChangePass(MerinfoChange merinfoChange, Operators op,
			AuditingItem auditing) throws ServiceException {
		// TODO Auto-generated method stub
		editSave(merinfoChange.getMid(), op, auditing);//保存 审核表信息
		try {
			//商户变更基本信息
			if ("C1".equals(merinfoChange.getDealCode())) {
				StringBuffer sql=new StringBuffer();
				List<Object> params=new ArrayList<Object>();
				sql.append("update TBL_MCHT_INF set OPER_IN ='U',REC_UPD_TS =? ,NAME_BUSI=? ,CONTACT_PHONENO=? ,CONTACT_NAME=?,CERTIF=? where MCHT_CD=?  ");
				    params.add(new Date());
				    params.add(merinfoChange.getNameBusi());
					params.add(merinfoChange.getContactPhoneNo());
					params.add(merinfoChange.getContactName());
					params.add(merinfoChange.getCertif());
					params.add(merinfoChange.getMid());
					merinfoChangeCheckDao.updateBySql(sql.toString(), params.toArray());
					//更新t_operators中信息 
					List<Object> params1=new ArrayList<Object>();
					String existSql=" from Operators   WHERE  accountNo=? ";
					params1.add(merinfoChange.getMid()); 
					List<Object> list=merinfoChangeCheckDao.queryAll(existSql, params1.toArray());
					if(!list.isEmpty())
					{
					StringBuffer opsql=new StringBuffer();
					List<Object> opparams=new ArrayList<Object>();
				    opsql.append("update t_operators set real_name=? ,mobile=?  where account_no=?  ");
				    opparams.add(merinfoChange.getNameBusi());
				    opparams.add(merinfoChange.getContactPhoneNo());
				    opparams.add(merinfoChange.getMid());
				    merinfoChangeCheckDao.updateBySql(opsql.toString(), opparams.toArray());
					}
					String querySql = " SELECT COUNT(1) FROM   posdbonl.t_pay_qrcode_bindmer WHERE MERCHANT_NO=? ";
					Object[] par={merinfoChange.getMid()};
					Object r = pageDao.findObj(querySql, par);
					long count = Long.parseLong(r.toString());
					if(count>0){
				  //生产		
					String url = "http://188.78.88.53:8001/qrcode-service/posMerchantMobileUpdate.do";
		       //测试
		         	//String url = "http://192.168.10.203:37002/qrcode-service/posMerchantMobileUpdate.do";
						JSONObject json = new JSONObject();
						json.put("acct_name", merinfoChange.getContactName());     //商户联系人
						json.put("merchant_name", merinfoChange.getNameBusi()); //商户简称
						json.put("MOBILE_NO", merinfoChange.getContactPhoneNo());     //手机号
						json.put("merchantNo", merinfoChange.getMid());               //商户号
						
						try {
//							String result=HttpClientUtil.httpPost(url, json);
//							logger.info("修改基本信息接口参数："+json+"返回结果：『" + result + "』。");
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					logger.info("-----变更商户基本信息成功后开始变更商户图片信息-------");
					//变更商户图片表中TBL_MCHT_PICTURE 中商户身份证正反面照片信息
					List<Object> parPic=new ArrayList<Object>();
					String  uptSql =" UPDATE apsmgm.TBL_MCHT_PICTURE T  SET t.url=? , T.REC_UPD_OPR=?,t.rec_opr_id=? ,t.rec_upd_ts=? where t.mcht_cd=?  and substr(t.pcode, 16, 2)=? " ;
					parPic.add(merinfoChange.getUrl2());
					parPic.add(op.getId());
					parPic.add("U");
					parPic.add(new Date());
					parPic.add(merinfoChange.getMid());
					parPic.add("01");
					merinfoChangeCheckDao.updateBySql(uptSql, parPic.toArray());
					parPic.set(0, merinfoChange.getUrl3());
					parPic.set(5, "02");  
					merinfoChangeCheckDao.updateBySql(uptSql, parPic.toArray());
					logger.info("-----变更商户基本信息成功后商户图片地址更新成功-------");
					
					merchantDao.addSyslog(SysLogType.MERINFO_CHANGE_AUDITING.getCode(),SysLogType.MERINFO_CHANGE_AUDITING.getName(),
					op.getAccountNo(), "操作员【" + op.getAccountNo()+ "】，商户【" + merinfoChange.getMid()+ "】变更商户基本信息成功！");	
			}//商户变更结算信息
				else if ("C2".equals(merinfoChange.getDealCode())) {
		    StringBuffer sql=new StringBuffer();
				List<Object> params=new ArrayList<Object>();
				sql.append("update TBL_MCHT_BANKACCOUNT SET OPER_IN ='U',REC_UPD_TS=? ,NAME=?,ACCOUNT=?,BANK_NAME=?,BANK_CODE=? where OWNER_CD=?  ");	
				params.add(new Date());
				params.add(merinfoChange.getBankAccountName() );
				params.add(merinfoChange.getBankAccount());
				params.add(merinfoChange.getOpenBank());
				params.add(merinfoChange.getBankCode());
				params.add(merinfoChange.getMid());
				merinfoChangeCheckDao.updateBySql(sql.toString(), params.toArray());
				
				 StringBuffer mersql=new StringBuffer();
				 List<Object> merparams=new ArrayList<Object>();
				 mersql.append(" UPDATE  tbl_mcht_inf   SET OPER_IN=? ,REC_UPD_TS=? ,APPROVALUSERNAME= ?, DVP_BY=?  , STLM_WAY_DESC=?  WHERE MCHT_CD=? ");
				 merparams.add("U");
				 merparams.add(new Date());
				 merparams.add(merinfoChange.getPubOrPri());
				 merparams.add(merinfoChange.getDvpBy().trim());//是否法人结算账户
				 merparams.add(merinfoChange.getStlmWayDesc());//非法人的身份证
			     merparams.add(merinfoChange.getMid());
				 merinfoChangeCheckDao.updateBySql(mersql.toString(), merparams.toArray());
				
				 //变更apstfr.tbl_jump_mcht_inf 表状态--2017-12-07;
				 String updjump =" UPDATE apstfr.tbl_jump_mcht_inf t SET t.status='0', t.remark1='0', t.rec_tm=? WHERE  mcht_cd=?  ";
				 List<Object> jumpparams=new ArrayList<Object>();
				 jumpparams.add(new Date());
				 jumpparams.add(merinfoChange.getMid());
				 merinfoChangeCheckDao.updateBySql(updjump, jumpparams.toArray());
				 
				 //删除apsmgm.t_wechat_validate表信息 
				 String del_we = " DELETE  FROM t_wechat_validate  WHERE open_id=? ";
				 Object[] wePar={merinfoChange.getMid()}; 
				 merinfoChangeCheckDao.updateBySql(del_we,wePar);
				 
				 
				 
				 //查询t_operators 是否有商户信息  有则变更结算信息
				List<Object> params1=new ArrayList<Object>();
				String existSql=" from Operators  t WHERE  t.accountNo=? ";
				params1.add(merinfoChange.getMid()); 
				List<Object> list=merinfoChangeCheckDao.queryAll(existSql, params1.toArray());
				if(!list.isEmpty())
				{
				StringBuffer opsql=new StringBuffer();
				List<Object> opparams=new ArrayList<Object>();
			    opsql.append("update t_operators set bank_acct_name=? ,bank_acct_no=? , bank_deposit=? , bank_no=?   where account_no=? ");		    
			    opparams.add(merinfoChange.getBankAccountName());
			    opparams.add(merinfoChange.getBankAccount());
			    opparams.add(merinfoChange.getOpenBank());
			    opparams.add(merinfoChange.getBankCode());
			    opparams.add(merinfoChange.getMid());
			    merinfoChangeCheckDao.updateBySql(opsql.toString(), opparams.toArray());
				}
				logger.info("调用接口变更");
				String querySql = " SELECT COUNT(1) FROM   posdbonl.t_pay_qrcode_bindmer WHERE MERCHANT_NO=? ";
				Object[] par={merinfoChange.getMid()};
				Object r = pageDao.findObj(querySql, par);
				long count = Long.parseLong(r.toString());
				if(count>0){
					Map<String,String> map=ConfigProperties.getSysDB1("UP_BC_CD",true);
					String branId=merinfoChange.getBankCode().substring(0, 3);  // 银行id
					String branName =map.get(branId);    // 银行名称
					//生产
					String url_1= "http://188.78.88.53:8001/qrcode-service/posSettleUpdate.do";
			       // 测试
			      // String url_1 = "http://192.168.10.203:37002/qrcode-service/posSettleUpdate.do";
					JSONObject json_1 = new JSONObject();
					json_1.put("merchantNo",merinfoChange.getMid());            //商户号
					json_1.put("CARD_NO",merinfoChange.getBankAccount());       //银行卡号
					json_1.put("ACCT_NAME",merinfoChange.getBankAccountName()); //名字
					json_1.put("MOBILE_NO",null);                               //手机号
					json_1.put("BANK_ID",branId);                               //银行id
					json_1.put("BANK_NAME",branName);                           //银行名字
					json_1.put("BANK_BRANCHID",merinfoChange.getBankCode());    //分行ID
					json_1.put("BANK_BRANCHNAME",merinfoChange.getOpenBank());  //分行名字
					    try {
							String result=HttpClientUtil.httpPost(url_1, json_1);
							logger.info("修改结算卡信息接口参数："+json_1+"返回结果：『" + result + "』。");
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
				}
				
				merchantDao.addSyslog(SysLogType.MERINFO_CHANGE_AUDITING.getCode(),SysLogType.MERINFO_CHANGE_AUDITING.getName(),
					op.getAccountNo(), "操作员【" + op.getAccountNo()+ "】，商户【" + merinfoChange.getMid()+ "】变更结算信息成功！");
		
			}//商户增机申请
			else if ("C3".equals(merinfoChange.getDealCode())) {
				List<Object> params_max=new ArrayList<Object>();
				String sql_max = "select max(term_id) FROM TBL_TERM_INF  where  mcht_cd=? ";
				params_max.add(merinfoChange.getMid());
				List<?> max = merinfoChangeCheckDao.queryBySqlToVo(sql_max, params_max.toArray());	
				List<Object> params1=new ArrayList<Object>();
				StringBuffer hql=new StringBuffer("  FROM   TblEditTermInf   "
						+ "  where MCHT_CD =? and  Status='10'  "  );
				params1.add(merinfoChange.getMid());
				List<?> tremlist = merinfoChangeCheckDao.queryAll(hql.toString(), params1.toArray());
				String maxreal = "";
				if(!max.isEmpty()){
					Object[] objc= max.toArray();
					String maxr =(String) objc[0];
					maxreal=getMax(maxr);
				} 
				StringBuffer sb =new StringBuffer();
				for (Object obj: tremlist) {
					TblEditTermInf tblEdit =(TblEditTermInf) obj;
					if("10".equals(tblEdit.getStatus())){
						TblTermInf tbl_real=new TblTermInf(); 
						/**
						 * 将 临时表对象的信息 复制到 正式表对象
						 */
						TblTermInfId tbl_real_id=new TblTermInfId(); 
						if("".equals(maxreal))
							tbl_real_id.setTermId(tblEdit.getId().getTermId());
						else
							tbl_real_id.setTermId(maxreal);		
						tbl_real_id.setMchtCd(tblEdit.getId().getMchtCd());
						tbl_real.setId(tbl_real_id);
						tbl_real.setTermTp(tblEdit.getTermTp());
						tbl_real.setBelong(tblEdit.getBelong());
						tbl_real.setBelongSub(tblEdit.getBelongSub());
				        tbl_real.setTmnlMoneyIntype(tblEdit.getTmnlMoneyIntype());
				        tbl_real.setTmnlMoney(tblEdit.getTmnlMoney());
						tbl_real.setTmnlBrand(tblEdit.getTmnlBrand());
						tbl_real.setTmnlModelNo(tblEdit.getTmnlModelNo());
						tbl_real.setTmnlBarcode(tblEdit.getTmnlBarcode());
						tbl_real.setDeviceCd(tblEdit.getDeviceCd());
						tbl_real.setInstalllocation(tblEdit.getInstalllocation());
						tbl_real.setTmnlIntype(tblEdit.getTmnlIntype());
						tbl_real.setDialOut(tblEdit.getDialOut());
						tbl_real.setDealTypes(tblEdit.getDealTypes());
						tbl_real.setRecOprId("I");
						tbl_real.setRecUpdOpr(tblEdit.getRecUpdOpr());
						tbl_real.setRecCrtTs(new Date());//增加  系统时间						
						tbl_real.setRecUpdTs(tblEdit.getRecUpdTs());
						tbl_real.setAppCd(tblEdit.getAppCd());
						tbl_real.setStatus("01");
						tbl_real.setActiveCode(tblEdit.getActiveCode());						
						merinfoChangeCheckDao.editSave(tbl_real);
						sb.append(maxreal+",");//添加的终端号
						maxreal=getMax(maxreal);
						List<Object> paramsCfg=new ArrayList<Object>();
						String editCfgSql ="from TblEditTermRiskCfg where MCHT_CD=? and TERM_ID =?" ;
						paramsCfg.add(merinfoChange.getMid());
						paramsCfg.add(tblEdit.getId().getTermId());
						List<?> mchtcfglist = merinfoChangeCheckDao.queryAll(editCfgSql.toString(), paramsCfg.toArray());					
						for(int i=0;i<mchtcfglist.size();i++)
						{
							TblEditTermRiskCfg tblEditCfg=(TblEditTermRiskCfg) mchtcfglist.get(i);
							TblTermRiskCfg    tblCfg  = new TblTermRiskCfg();
							TblTermRiskCfgId  tblriskId = new TblTermRiskCfgId();
							   tblriskId.setMchtCd(tblEditCfg.getId().getMchtCd());
							   tblriskId.setTermId(tbl_real_id.getTermId());
							   tblCfg.setId(tblriskId);
								if(i==0)
								tblriskId.setCardType("00");
								if(i==1)
									tblriskId.setCardType("01");
								if(!"".equals(tblEditCfg.getTotalLimitmoney())){
								tblCfg.setTotalLimitmoney(Double.valueOf("1000000.00"));
								}
								tblCfg.setAccpetStartTime(tblEditCfg.getAccpetStartTime());
								tblCfg.setAccpetStartDate(tblEditCfg.getAccpetStartDate());
								tblCfg.setAccpetEndTime(tblEditCfg.getAccpetEndTime());
								tblCfg.setAccpetEndDate(tblEditCfg.getAccpetEndDate());
							if(!"".equals(tblEditCfg.getSingleLimitmoney())){
								tblCfg.setSingleLimitmoney(Double.valueOf("100000.00"));
						    	}
								tblCfg.setControlWay(tblEditCfg.getControlWay());
							if(!"".equals(tblEditCfg.getSingleMinMoney())){
								tblCfg.setSingleMinMoney(Double.valueOf("1.00"));
							}
								tblCfg.setTotalPeriod(tblEditCfg.getTotalPeriod());
								tblCfg.setRecUpdTs(tblEditCfg.getRecUpdTs());
								tblCfg.setRecCrtTs(new Date());
								tblCfg.setRecOprId(tblEditCfg.getRecOprId());
								tblCfg.setRecUpdOpr(op.getRealName());
								tblCfg.setOperIn("I");
								merinfoChangeCheckDao.editSave(tblCfg);
						}	
					}	
				}
				String sql_update=" update  t_merinfo_change set terid=? where mid=? and status='L' " ;
				Object[] updateParams={sb.toString(),merinfoChange.getMid()}; 
				merinfoChangeCheckDao.updateBySql(sql_update,updateParams);
				String deleteOld="delete from TBL_EDIT_TERM_INF where MCHT_CD =? and  Status='10' ";
				merinfoChangeCheckDao.updateBySql(deleteOld, new Object[]{merinfoChange.getMid()});
				//删除终端信息（临时表）
				String sql_dele=" DELETE  FROM TBL_EDIT_TERM_INF WHERE MCHT_CD=? and  Status='10'  " ;
				Object[] insertParams={
						merinfoChange.getMid(),
				}; 
				merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);
				//删除终端风控信息（临时表）
				String sql_cfg = "DELETE FROM TBL_EDIT_TERM_RISK_CFG  WHERE  MCHT_CD=? ";
				Object[] cfg_params={
						merinfoChange.getMid(),
				}; 
				merinfoChangeCheckDao.updateBySql(sql_cfg,cfg_params);			
				merchantDao.addSyslog(SysLogType.MERINFO_CHANGE_AUDITING.getCode(),SysLogType.MERINFO_CHANGE_AUDITING.getName(),
					op.getAccountNo(), "操作员【" + op.getAccountNo()+ "】，商户【" + merinfoChange.getMid()+ "】商户赠机成功！");
			}	
			//申请变更T1手续费
			else if ("C4".equals(merinfoChange.getDealCode())) {
				List<Object> params_fee=new ArrayList<Object>();
				StringBuffer hql_fee=new StringBuffer(" select *    FROM   TBL_EDIT_MCHT_BIZ_FEE   "
						+ "  where MCHT_CD =? and PROD_CD=?  "  );
				params_fee.add(merinfoChange.getMid());
				params_fee.add(ConfigMerinfoUtil.T1_FUNCTION);
				List<?> tblMchtFees = merinfoChangeCheckDao.queryBySqlToVo(hql_fee.toString(), params_fee.toArray());
				for (Object object : tblMchtFees) {
					Object[] obj=(Object[]) object;
					String hqlFindTbl="from TblMchtBizFee where mchtCd =? and prodCd=? and bizCd=? and subBizCd=? ";//查询数据库中是否有这条数据
					Object[] parmasReal={obj[0],obj[1],obj[2],obj[3]};
					List<?> tblMchReals=merinfoChangeCheckDao.queryAll(hqlFindTbl.toString(), parmasReal);
					if(tblMchReals.isEmpty())
					{
						//添加 
						String insertRealSql="insert into TBL_MCHT_BIZ_FEE values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
						
						Object[] insertParams={
								obj[0],
								obj[1],
								obj[2],
								obj[3],
								obj[4],
								obj[5],
								obj[6],
								obj[7],
								obj[8],
								obj[9],
								obj[10],
								obj[11],
								obj[12],
								obj[13],
								obj[14],
								"I",
								obj[16],
								obj[17],
								new Date(),
								obj[19]
								
						};
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}else{
						//修改
						String insertRealSql="update TBL_MCHT_BIZ_FEE  set "
								+ " MCHT_FEE_MD=?,MCHT_FEE_PERCENT=?,MCHT_FEE_PCT_MIN=?,MCHT_FEE_PCT_MAX=?, "
								+ "  MCHT_FEE_SINGLE=?,MCHT_A_FEE_SAME=?,MCHT_A_FEE_MD=?,MCHT_A_FEE_PERCENT=?, "
								+ " MCHT_A_FEE_PCT_MIN=?,MCHT_A_FEE_PCT_MAX=?,MCHT_A_FEE_SINGLE=?,OPER_IN=?,REC_OPR_ID=?, "
								+ " REC_UPD_OPR=?,REC_UPD_TS=? "
								+ "where  MCHT_CD=? and PROD_CD=? and BIZ_CD=? and SUB_BIZ_CD=? ";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
						if(obj[19]==null)
							obj[19]=new Date();
				
						Object[] insertParams={
								
								obj[4],
								obj[5],
								obj[6],
								obj[7],
								obj[8],
								obj[9],
								obj[10],
								obj[11],
								obj[12],
								obj[13],
								obj[14],
								"U",
								obj[16],
								obj[17],
								new Date(),
								obj[0],
								obj[1],
								obj[2],
								obj[3]
								
						};
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}
			    //删除手续费信息（临时表）
				String sql_dele=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
				Object[] insertParams={
						merinfoChange.getMid(),
				}; 
				merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);
				
				merchantDao.addSyslog(
						SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
						SysLogType.MERINFO_CHANGE_AUDITING.getName(),
						op.getAccountNo(), "操作员【" + op.getAccountNo()
								+ "】，商户【" + merinfoChange.getMid()
								+ "】变更T1手续费成功！");
			     }
			}
			
			//申请变更T0手续费
			else if ("C5".equals(merinfoChange.getDealCode())) {
				List<Object> params_fee=new ArrayList<Object>();
				
				StringBuffer hql_fee=new StringBuffer(" select *    FROM   TBL_EDIT_MCHT_BIZ_FEE   "
						+ "  where MCHT_CD =? and PROD_CD=?  "  );
				params_fee.add(merinfoChange.getMid());
				params_fee.add(ConfigMerinfoUtil.T0_FUNCTION);
				List<?> tblMchtFees = merinfoChangeCheckDao.queryBySqlToVo(hql_fee.toString(), params_fee.toArray());
				for (Object object : tblMchtFees) {
					Object[] obj=(Object[]) object;
				//	TblEditMchtBizFee tblEditFee=(TblEditMchtBizFee) object;
					String hqlFindTbl="from TblMchtBizFee where mchtCd =? and prodCd=? and bizCd=? and subBizCd=? ";//查询数据库中是否有这条数据
					Object[] parmasReal={obj[0],obj[1],obj[2],obj[3]};
					List<?> tblMchReals=merinfoChangeCheckDao.queryAll(hqlFindTbl.toString(), parmasReal);
					if(tblMchReals.isEmpty())
					{
						//添加 
						String insertRealSql="insert into TBL_MCHT_BIZ_FEE values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
						
				
						Object[] insertParams={
								obj[0],
								obj[1],
								obj[2],
								obj[3],
								obj[4],
								obj[5],
								obj[6],
								obj[7],
								obj[8],
								obj[9],
								obj[10],
								obj[11],
								obj[12],
								obj[13],
								obj[14],
								"I",
								obj[16],
								obj[17],
								new Date(),
								obj[19]
								
						};
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}else{
						//修改
						String insertRealSql="update TBL_MCHT_BIZ_FEE  set "
								+ " MCHT_FEE_MD=?,MCHT_FEE_PERCENT=?,MCHT_FEE_PCT_MIN=?,MCHT_FEE_PCT_MAX=?, "
								+ "  MCHT_FEE_SINGLE=?,MCHT_A_FEE_SAME=?,MCHT_A_FEE_MD=?,MCHT_A_FEE_PERCENT=?, "
								+ " MCHT_A_FEE_PCT_MIN=?,MCHT_A_FEE_PCT_MAX=?,MCHT_A_FEE_SINGLE=?,OPER_IN=?,REC_OPR_ID=?, "
								+ " REC_UPD_OPR=?,REC_UPD_TS=? "
								+ "where  MCHT_CD=? and PROD_CD=? and BIZ_CD=? and SUB_BIZ_CD=? ";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
					
						Object[] insertParams={	obj[4],obj[5],obj[6],obj[7],obj[8],obj[9],obj[10],	obj[11],obj[12],
								obj[13],
								obj[14],
								"U",
								obj[16],
								obj[17],
								new Date(),
								obj[0],
								obj[1],
								obj[2],
								obj[3]
								
						};
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}
				//删除手续费信息（临时表）
				String sql_dele=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
				Object[] insertParams={
						merinfoChange.getMid(),
				}; 
				merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);  
				
				merchantDao.addSyslog(
						SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
						SysLogType.MERINFO_CHANGE_AUDITING.getName(),
						op.getAccountNo(), "操作员【" + op.getAccountNo()
								+ "】，商户【" + merinfoChange.getMid()
								+ "】变更T0手续费成功！");
				}	
			}//商户申请T1开通
			else if ("C6".equals(merinfoChange.getDealCode())) {
                       //开通T1
				List<Object> deal_params=new ArrayList<Object>();
				StringBuffer deal_sql=new StringBuffer("  SELECT * FROM   TBL_EDIT_MCHT_BIZ_DEAL   "
						+ "  where MCHT_CD =?  AND PROD_CD=?  "  );
				
				deal_params.add(merinfoChange.getMid());
				deal_params.add(ConfigMerinfoUtil.T1_FUNCTION);
				List<?> mchtBiz =merinfoChangeCheckDao.queryBySqlToVo(deal_sql.toString(), deal_params.toArray());
				for (Object objects : mchtBiz) {
					Object[] objs=(Object[]) objects;
					String hqlFindTblDeal="from TblMchtBizDeal where mchtCd =? and prodCd=? and bizCd=? and transCd=? ";//查询数据库中是否有这条数据
					Object[] parmasDeal={objs[0],objs[1],objs[2],objs[3]};
					List<?> tblMchDeal=merinfoChangeCheckDao.queryAll(hqlFindTblDeal.toString(), parmasDeal);
					if(tblMchDeal.isEmpty())
					{
						//添加
						String  insertDealSql ="insert into TBL_MCHT_BIZ_DEAL(MCHT_CD,PROD_CD,BIZ_CD,TRANS_CD,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS) values(?,?,?,?,?,?,?,? )";
						Object[] insertParams={objs[0],  objs[1], objs[2], objs[3], "I", objs[5], objs[6],
								new Date()	};
						merinfoChangeCheckDao.updateBySql(insertDealSql,insertParams);
					}
				}	
				//添加手续费
		 		List<Object> params_fee=new ArrayList<Object>();
				StringBuffer hql_fee=new StringBuffer(" select *    FROM   TBL_EDIT_MCHT_BIZ_FEE   "
						+ "  where MCHT_CD =? and PROD_CD=?  "  );
				params_fee.add(merinfoChange.getMid());
				params_fee.add(ConfigMerinfoUtil.T1_FUNCTION);
				List<?> tblMchtFees = merinfoChangeCheckDao.queryBySqlToVo(hql_fee.toString(), params_fee.toArray());
				for (Object object : tblMchtFees) {
					Object[] obj=(Object[]) object;
					String hqlFindTbl="from TblMchtBizFee where mchtCd =? and prodCd=? and bizCd=? and subBizCd=? ";//查询数据库中是否有这条数据
					Object[] parmasReal={obj[0],obj[1],obj[2],obj[3]};
					List<?> tblMchReals=merinfoChangeCheckDao.queryAll(hqlFindTbl.toString(), parmasReal);
					if(tblMchReals.isEmpty())
					{
						//添加 
						String insertRealSql="insert into TBL_MCHT_BIZ_FEE  "
								+ " ( MCHT_CD,PROD_CD,BIZ_CD,SUB_BIZ_CD,MCHT_FEE_MD,MCHT_FEE_PERCENT,MCHT_FEE_PCT_MIN,MCHT_FEE_PCT_MAX,MCHT_FEE_SINGLE,MCHT_A_FEE_SAME,    "
								+ " MCHT_A_FEE_MD,MCHT_A_FEE_PERCENT,MCHT_A_FEE_PCT_MIN,MCHT_A_FEE_PCT_MAX,MCHT_A_FEE_SINGLE,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS  )  "
								+ " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
						
						Object[] insertParams={obj[0], obj[1], obj[2], obj[3], obj[4], obj[5], obj[6], obj[7],
								 obj[8], obj[9], obj[10], obj[11], obj[12], obj[13], obj[14], "I",
								 obj[16], obj[17], new Date() };
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}else{
						//修改
						String insertRealSql="update TBL_MCHT_BIZ_FEE  set "
								+ " MCHT_FEE_MD=?,MCHT_FEE_PERCENT=?,MCHT_FEE_PCT_MIN=?,MCHT_FEE_PCT_MAX=?, "
								+ "  MCHT_FEE_SINGLE=?,MCHT_A_FEE_SAME=?,MCHT_A_FEE_MD=?,MCHT_A_FEE_PERCENT=?, "
								+ " MCHT_A_FEE_PCT_MIN=?,MCHT_A_FEE_PCT_MAX=?,MCHT_A_FEE_SINGLE=?,OPER_IN=?,REC_OPR_ID=?, "
								+ " REC_UPD_OPR=?,REC_UPD_TS=? "
								+ "where  MCHT_CD=? and PROD_CD=? and BIZ_CD=? and SUB_BIZ_CD=? ";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
						if(obj[19]==null)
							obj[19]=new Date();
				
						Object[] insertParams={obj[4],obj[5],obj[6],	obj[7],	obj[8],obj[9],obj[10],obj[11],obj[12],
								obj[13],obj[14],	"U",	obj[16],	obj[17],	new Date(),	obj[0],	obj[1],obj[2],obj[3]	};
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}
				String sql_dele=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
				Object[] insertParams={
						merinfoChange.getMid(),
				}; 
				merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);  
				merchantDao.addSyslog(
						SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
						SysLogType.MERINFO_CHANGE_AUDITING.getName(),
						op.getAccountNo(), "操作员【" + op.getAccountNo()
								+ "】，商户【" + merinfoChange.getMid()
								+ "】变更T0手续费成功！");
				}	
				
			}//商户申请T0开通
			else if ("C7".equals(merinfoChange.getDealCode())) {
		       //开通t0
				
				List<Object> deal_params=new ArrayList<Object>();
				StringBuffer deal_sql=new StringBuffer("  SELECT * FROM   TBL_EDIT_MCHT_BIZ_DEAL   "
						+ "  where MCHT_CD =?  AND PROD_CD=?  "  );
				
				deal_params.add(merinfoChange.getMid());
				deal_params.add(ConfigMerinfoUtil.T0_FUNCTION);
				List<?> mchtBiz =merinfoChangeCheckDao.queryBySqlToVo(deal_sql.toString(), deal_params.toArray());
				for (Object objects : mchtBiz) {
					Object[] objs=(Object[]) objects;
					String hqlFindTblDeal="from TblMchtBizDeal where mchtCd =? and prodCd=? and bizCd=? and transCd=? ";//查询数据库中是否有这条数据
					Object[] parmasDeal={objs[0],objs[1],objs[2],objs[3]};
					List<?> tblMchDeal=merinfoChangeCheckDao.queryAll(hqlFindTblDeal.toString(), parmasDeal);
					if(tblMchDeal.isEmpty())
					{
						//添加
						String  insertDealSql ="insert into TBL_MCHT_BIZ_DEAL(MCHT_CD,PROD_CD,BIZ_CD,TRANS_CD,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS) values(?,?,?,?,?,?,?,? )";
						
						Object[] insertParams={	 objs[0], objs[1], objs[2],  objs[3],  "I",  objs[5],
								objs[6],  new Date()   };
						merinfoChangeCheckDao.updateBySql(insertDealSql,insertParams);
					}
				}			
				//添加手续费
            	List<Object> params_fee=new ArrayList<Object>();
				StringBuffer hql_fee=new StringBuffer(" select *    FROM   TBL_EDIT_MCHT_BIZ_FEE   "
						+ "  where MCHT_CD =? and PROD_CD=?  "  );
				params_fee.add(merinfoChange.getMid());
				params_fee.add(ConfigMerinfoUtil.T0_FUNCTION);
				List<?> tblMchtFees = merinfoChangeCheckDao.queryBySqlToVo(hql_fee.toString(), params_fee.toArray());
				for (Object object : tblMchtFees) {
					Object[] obj=(Object[]) object;
					String hqlFindTbl="from TblMchtBizFee where mchtCd =? and prodCd=? and bizCd=? and subBizCd=? ";//查询数据库中是否有这条数据
					Object[] parmasReal={obj[0],obj[1],obj[2],obj[3]};
					List<?> tblMchReals=merinfoChangeCheckDao.queryAll(hqlFindTbl.toString(), parmasReal);
					if(tblMchReals.isEmpty())
					{
						//添加 
						String insertRealSql="insert into TBL_MCHT_BIZ_FEE"
								+ "  ( MCHT_CD,PROD_CD,BIZ_CD,SUB_BIZ_CD,MCHT_FEE_MD,MCHT_FEE_PERCENT,MCHT_FEE_PCT_MIN,MCHT_FEE_PCT_MAX,MCHT_FEE_SINGLE,MCHT_A_FEE_SAME,    "
								+ " MCHT_A_FEE_MD,MCHT_A_FEE_PERCENT,MCHT_A_FEE_PCT_MIN,MCHT_A_FEE_PCT_MAX,MCHT_A_FEE_SINGLE,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS )  "
								+ " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						if(obj[5]==null)
							obj[5]=0.0;
						if(obj[6]==null)
							obj[6]=0.0;
						if(obj[7]==null)
							obj[7]=0.0;
						if(obj[8]==null)
							obj[8]=0.0;
						if(obj[11]==null)
							obj[11]=0.0;
						if(obj[12]==null)
							obj[12]=0.0;
						if(obj[13]==null)
							obj[13]=0.0;
						if(obj[14]==null)
							obj[14]=0.0;
						
				
						Object[] insertParams={obj[0],obj[1],obj[2],obj[3],obj[4],obj[5],obj[6],obj[7],obj[8],obj[9],
								obj[10],obj[11],obj[12],obj[13],obj[14],"I",obj[16],obj[17],new Date() };
						merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
					}				
				String sql_delete=" DELETE  FROM TBL_EDIT_MCHT_BIZ_DEAL  WHERE MCHT_CD=?   " ;
				Object[] deleteParams={
						merinfoChange.getMid(),
				}; 
				merinfoChangeCheckDao.updateBySql(sql_delete,deleteParams);
				
				String sql_dele=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
				Object[] insertParams={merinfoChange.getMid()}; 
				merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);
				merchantDao.addSyslog(
						SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
						SysLogType.MERINFO_CHANGE_AUDITING.getName(),
						op.getAccountNo(), "操作员【" + op.getAccountNo()
								+ "】，商户【" + merinfoChange.getMid()
								+ "】商户申请T0开通成功！");
			      }	
			}//终止合同申请
			else if ("C8".equals(merinfoChange.getDealCode())) {
				StringBuffer sql=new StringBuffer();
				List<Object> params=new ArrayList<Object>();
				sql.append("UPDATE TBL_MCHT_INF SET OPER_IN='U',REC_UPD_TS=?,STATUS=? WHERE MCHT_CD=?");
				params.add(new Date());//系统时间
				params.add("02");
				params.add(merinfoChange.getMid());
				merinfoChangeCheckDao.updateBySql(sql.toString(), params.toArray());
				//变更表posdbonl.tbl_mgm_term_tkey状态
				StringBuffer sql_term_tkey=new StringBuffer();
				params.clear();
				sql_term_tkey.append("update posdbonl.tbl_mgm_term_tkey   set random       = '000000',  "
						+ " pub_key_data = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', "
						+ "sec_key_data = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' "
						+ " where mcht_cd =?  ");
				params.add(merinfoChange.getMid());
				merinfoChangeCheckDao.updateBySql(sql_term_tkey.toString(), params.toArray());
				StringBuffer sql_term_wkey=new StringBuffer();
				sql_term_wkey.append("update posdbonl.tbl_mgm_term_wkey"
						+ "   set mac_key     = 'FFFFFFFFFFFFFFFF', "
						+ "  mac_key_chk = 'FFFFFFFFFFFFFFFF', "
						+ "  pin_key     = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', "
						+ "    pin_key_chk = 'FFFFFFFFFFFFFFFF', "
						+ "   trk_key     = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', "
						+ "    trk_key_chk = 'FFFFFFFFFFFFFFFF' "
						+ "  where mcht_cd =? ");
				merinfoChangeCheckDao.updateBySql(sql_term_wkey.toString(), params.toArray());
				
				
				merchantDao.addSyslog(
						SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
						SysLogType.MERINFO_CHANGE_AUDITING.getName(),
						op.getAccountNo(), "操作员【" + op.getAccountNo()
								+ "】，商户【" + merinfoChange.getMid()
								+ "】商户终止合同成功！");
			}//银联扫码开通
			else if ("10".equals(merinfoChange.getDealCode())) {
			       //开通银联扫码
				
					List<Object> deal_params=new ArrayList<Object>();
					StringBuffer deal_sql=new StringBuffer("  SELECT * FROM   TBL_EDIT_MCHT_BIZ_DEAL   "
							+ "  where MCHT_CD =?  AND PROD_CD in('1191','1161','1691','1661')  "  );
					
					deal_params.add(merinfoChange.getMid());
					//deal_params.add(ConfigMerinfoUtil.UNIONPAY_FUNCTION);//银联扫码
					List<?> mchtBiz =merinfoChangeCheckDao.queryBySqlToVo(deal_sql.toString(), deal_params.toArray());
					for (Object objects : mchtBiz) {
						Object[] objs=(Object[]) objects;
						String hqlFindTblDeal="from TblMchtBizDeal where mchtCd =? and prodCd=? and bizCd=? and transCd=? ";//查询数据库中是否有这条数据
						Object[] parmasDeal={objs[0],objs[1],objs[2],objs[3]};
						List<?> tblMchDeal=merinfoChangeCheckDao.queryAll(hqlFindTblDeal.toString(), parmasDeal);
						if(tblMchDeal.isEmpty())
						{
							//添加产品信息
							String  insertDealSql ="insert into TBL_MCHT_BIZ_DEAL(MCHT_CD,PROD_CD,BIZ_CD,TRANS_CD,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS) values(?,?,?,?,?,?,?,? )";
							
							Object[] insertParams={	 objs[0], objs[1], objs[2],  objs[3],  "I",  objs[5],
									objs[6],  new Date()   };
							merinfoChangeCheckDao.updateBySql(insertDealSql,insertParams);
						}
					}			
					//添加手续费
	            	List<Object> params_fee=new ArrayList<Object>();
					StringBuffer hql_fee=new StringBuffer(" select *    FROM   TBL_EDIT_MCHT_BIZ_FEE   "
							+ "  where MCHT_CD =? and PROD_CD in('1191','1691')  "  );
					params_fee.add(merinfoChange.getMid());
					//params_fee.add(ConfigMerinfoUtil.UNIONPAY_FUNCTION);
					List<?> tblMchtFees = merinfoChangeCheckDao.queryBySqlToVo(hql_fee.toString(), params_fee.toArray());
					for (Object object : tblMchtFees) {
						Object[] obj=(Object[]) object;
						String hqlFindTbl="from TblMchtBizFee where mchtCd =? and prodCd=? and bizCd=? and subBizCd=? ";//查询数据库中是否有这条数据
						Object[] parmasReal={obj[0],obj[1],obj[2],obj[3]};
						List<?> tblMchReals=merinfoChangeCheckDao.queryAll(hqlFindTbl.toString(), parmasReal);
						if(tblMchReals.isEmpty())
						{
							//添加 
							String insertRealSql="insert into TBL_MCHT_BIZ_FEE"
									+ "  ( MCHT_CD,PROD_CD,BIZ_CD,SUB_BIZ_CD,MCHT_FEE_MD,MCHT_FEE_PERCENT,MCHT_FEE_PCT_MIN,MCHT_FEE_PCT_MAX,MCHT_FEE_SINGLE,MCHT_A_FEE_SAME,    "
									+ " MCHT_A_FEE_MD,MCHT_A_FEE_PERCENT,MCHT_A_FEE_PCT_MIN,MCHT_A_FEE_PCT_MAX,MCHT_A_FEE_SINGLE,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS )  "
									+ " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							if(obj[5]==null)
								obj[5]=0.0;
							if(obj[6]==null)
								obj[6]=0.0;
							if(obj[7]==null)
								obj[7]=0.0;
							if(obj[8]==null)
								obj[8]=0.0;
							if(obj[11]==null)
								obj[11]=0.0;
							if(obj[12]==null)
								obj[12]=0.0;
							if(obj[13]==null)
								obj[13]=0.0;
							if(obj[14]==null)
								obj[14]=0.0;
							
					
							Object[] insertParams={obj[0],obj[1],obj[2],obj[3],obj[4],obj[5],obj[6],obj[7],obj[8],obj[9],
									obj[10],obj[11],obj[12],obj[13],obj[14],"I",obj[16],obj[17],new Date() };
							merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
						}				
					String sql_delete=" DELETE  FROM TBL_EDIT_MCHT_BIZ_DEAL  WHERE MCHT_CD=?   " ;
					Object[] deleteParams={
							merinfoChange.getMid(),
					}; 
					merinfoChangeCheckDao.updateBySql(sql_delete,deleteParams);
					
					String sql_dele=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
					Object[] insertParams={merinfoChange.getMid()}; 
					merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);
					merchantDao.addSyslog(
							SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
							SysLogType.MERINFO_CHANGE_AUDITING.getName(),
							op.getAccountNo(), "操作员【" + op.getAccountNo()
									+ "】，商户【" + merinfoChange.getMid()
									+ "】商户申请银联扫码开通成功！");
				      }	
				}//支付宝/微信扫码开通
			else if ("11".equals(merinfoChange.getDealCode())) {
			       //开通支付宝/微信扫码
				
					List<Object> deal_params=new ArrayList<Object>();
					StringBuffer deal_sql=new StringBuffer("  SELECT * FROM   TBL_EDIT_MCHT_BIZ_DEAL   "
							+ "  where MCHT_CD =?  AND PROD_CD in('1291','1391','1491','1591','1261','1361','1461','1561')  "  );
					
					deal_params.add(merinfoChange.getMid());
					//deal_params.add(ConfigMerinfoUtil.ZWPAY_FUNCTION);//支付宝/微信扫码
					List<?> mchtBiz =merinfoChangeCheckDao.queryBySqlToVo(deal_sql.toString(), deal_params.toArray());
					for (Object objects : mchtBiz) {
						Object[] objs=(Object[]) objects;
						String hqlFindTblDeal="from TblMchtBizDeal where mchtCd =? and prodCd=? and bizCd=? and transCd=? ";//查询数据库中是否有这条数据
						Object[] parmasDeal={objs[0],objs[1],objs[2],objs[3]};
						List<?> tblMchDeal=merinfoChangeCheckDao.queryAll(hqlFindTblDeal.toString(), parmasDeal);
						if(tblMchDeal.isEmpty())
						{
							//添加产品信息
							String  insertDealSql ="insert into TBL_MCHT_BIZ_DEAL(MCHT_CD,PROD_CD,BIZ_CD,TRANS_CD,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS) values(?,?,?,?,?,?,?,? )";
							
							Object[] insertParams={	 objs[0], objs[1], objs[2],  objs[3],  "I",  objs[5],
									objs[6],  new Date()   };
							merinfoChangeCheckDao.updateBySql(insertDealSql,insertParams);
						}
					}			
					//添加手续费
	            	List<Object> params_fee=new ArrayList<Object>();
					StringBuffer hql_fee=new StringBuffer(" select *    FROM   TBL_EDIT_MCHT_BIZ_FEE   "
							+ "  where MCHT_CD =? and PROD_CD  in('1291','1391','1491','1591')  "  );
					params_fee.add(merinfoChange.getMid());
					//params_fee.add(ConfigMerinfoUtil.UNIONPAY_FUNCTION);
					List<?> tblMchtFees = merinfoChangeCheckDao.queryBySqlToVo(hql_fee.toString(), params_fee.toArray());
					for (Object object : tblMchtFees) {
						Object[] obj=(Object[]) object;
						String hqlFindTbl="from TblMchtBizFee where mchtCd =? and prodCd=? and bizCd=? and subBizCd=? ";//查询数据库中是否有这条数据
						Object[] parmasReal={obj[0],obj[1],obj[2],obj[3]};
						List<?> tblMchReals=merinfoChangeCheckDao.queryAll(hqlFindTbl.toString(), parmasReal);
						if(tblMchReals.isEmpty())
						{
							//添加 
							String insertRealSql="insert into TBL_MCHT_BIZ_FEE"
									+ "  ( MCHT_CD,PROD_CD,BIZ_CD,SUB_BIZ_CD,MCHT_FEE_MD,MCHT_FEE_PERCENT,MCHT_FEE_PCT_MIN,MCHT_FEE_PCT_MAX,MCHT_FEE_SINGLE,MCHT_A_FEE_SAME,    "
									+ " MCHT_A_FEE_MD,MCHT_A_FEE_PERCENT,MCHT_A_FEE_PCT_MIN,MCHT_A_FEE_PCT_MAX,MCHT_A_FEE_SINGLE,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS )  "
									+ " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							if(obj[5]==null)
								obj[5]=0.0;
							if(obj[6]==null)
								obj[6]=0.0;
							if(obj[7]==null)
								obj[7]=0.0;
							if(obj[8]==null)
								obj[8]=0.0;
							if(obj[11]==null)
								obj[11]=0.0;
							if(obj[12]==null)
								obj[12]=0.0;
							if(obj[13]==null)
								obj[13]=0.0;
							if(obj[14]==null)
								obj[14]=0.0;
							
					
							Object[] insertParams={obj[0],obj[1],obj[2],obj[3],obj[4],obj[5],obj[6],obj[7],obj[8],obj[9],
									obj[10],obj[11],obj[12],obj[13],obj[14],"I",obj[16],obj[17],new Date() };
							merinfoChangeCheckDao.updateBySql(insertRealSql,insertParams);
						}				
					
				      }	
					String sql_delete=" DELETE  FROM TBL_EDIT_MCHT_BIZ_DEAL  WHERE MCHT_CD=?   " ;
					Object[] deleteParams={
							merinfoChange.getMid(),
					}; 
					merinfoChangeCheckDao.updateBySql(sql_delete,deleteParams);
					
					String sql_dele=" DELETE  FROM TBL_EDIT_MCHT_BIZ_FEE WHERE MCHT_CD=?   " ;
					Object[] insertParams={merinfoChange.getMid()}; 
					merinfoChangeCheckDao.updateBySql(sql_dele,insertParams);
					merchantDao.addSyslog(
							SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
							SysLogType.MERINFO_CHANGE_AUDITING.getName(),
							op.getAccountNo(), "操作员【" + op.getAccountNo()
									+ "】，商户【" + merinfoChange.getMid()
									+ "】商户申请支付宝/微信扫码开通成功！");
				}else if ("12".equals(merinfoChange.getDealCode())) {
				       //开通预授权  添加产品信息
					           //预授权1021
								String  insertDealSql ="insert into TBL_MCHT_BIZ_DEAL(MCHT_CD,PROD_CD,BIZ_CD,TRANS_CD,OPER_IN,REC_OPR_ID,REC_UPD_OPR,REC_CRT_TS) values(?,?,?,?,?,?,?,? )";
								List<Object> parmas=new ArrayList<Object>();
								parmas.add(merinfoChange.getMid()); //商户号
								parmas.add("1000"); //产品码
								parmas.add("0000000");   // 主业务吗
								parmas.add("1021");   //开通交易类型
								parmas.add("I"); // I OR  U
								parmas.add("");  //操作类型
								parmas.add(op.getId());  //操作员
								parmas.add(new Date());  //生成时间
								sqlBaseDao.deleteBySql(insertDealSql, parmas);
//								merinfoChangeCheckDao.updateBySql(insertDealSql,parmas.toArray());
								//添加预授权完成
								parmas.set(3, "1031");  
								sqlBaseDao.deleteBySql(insertDealSql, parmas);
								
								//添加预授权撤销
								parmas.set(3, "2021");  
								sqlBaseDao.deleteBySql(insertDealSql, parmas);
								//添加预授权完成撤销
								parmas.set(3, "2031");  
								sqlBaseDao.deleteBySql(insertDealSql, parmas);
								//退货
								parmas.set(3, "3011");  
								sqlBaseDao.deleteBySql(insertDealSql, parmas);

						merchantDao.addSyslog(
								SysLogType.MERINFO_CHANGE_AUDITING.getCode(),
								SysLogType.MERINFO_CHANGE_AUDITING.getName(),
								op.getAccountNo(), "操作员【" + op.getAccountNo()
										+ "】，商户【" + merinfoChange.getMid()
										+ "】商户申请开通预授权成功！");
					}
			
		
			StringBuffer updateChangeSql = new StringBuffer();
			List<Object> paramsChange =new ArrayList<Object>();
			  updateChangeSql.append("  update  t_merinfo_change set OPERATORS=?, status=?, DT_AUDITOR_TIME=?,REMARK=? where  STATUS='L' and MID=?   ");
			  paramsChange.add(op.getRealName());
			  paramsChange.add("Y");
			  paramsChange.add(new Date());
			  paramsChange.add(auditing.getResult_detail());
			  paramsChange.add(merinfoChange.getMid());
			  
			  merinfoChangeCheckDao.updateBySql(updateChangeSql.toString(), paramsChange.toArray());
			
			  StringBuffer updateChangerecSql = new StringBuffer();
			  List<Object> paramsChangerec =new ArrayList<Object>();
			  updateChangerecSql.append(" UPDATE T_CHANGE_RECEIVE  SET STATUS=? WHERE STATUS=? AND MERNO=?  ");
			  paramsChangerec.add("1");
			  paramsChangerec.add("0");
			  paramsChangerec.add(merinfoChange.getMid());
			  merinfoChangeCheckDao.updateBySql(updateChangerecSql.toString(), paramsChangerec.toArray());
			  
			  logger.info("------------------------商户【"+merinfoChange.getMid()+"】变更【"+merinfoChange.getDealCode()+"】审核成功--------------------");
		} catch (DaoException e) {
			// TODO Auto-generated catch block
			logger.error("商户审核修改基本信息失败", e);
			throw new ServiceException("商户审核修改基本信息失败");
		}
	}
	
	private String getMax(String max)
	{
		Long maxlong=Long.parseLong(max);
		maxlong+=1;
		StringBuffer maxreal=new StringBuffer();
		int  zeroleng=max.length()-maxlong.toString().length();
		for (int i = 0; i < zeroleng; i++) {
			maxreal.append("0");
		}
		maxreal.append(maxlong);
		return maxreal.toString();
	}
	/**
	 * 查询商户原始信息
	 */

	@Override
	@Transactional(readOnly=true)
	public TblMchtInf queryMerinfoDetailInfo(String merinfoNo, boolean showName,String rkType )
			throws ServiceException {
		TblMchtInf mer_info=null;
		 
		 Object[] param={merinfoNo};
		 try {
			if(null==merinfoNo) return mer_info; //为空返回
			
			//商户信息
			String mer_hql=" from TblMchtInf t where t.id=?";
			mer_info=(TblMchtInf)pageDao.createQueryUniqueResult(mer_hql,param );
			if(null!=rkType && !rkType.equals("1")){
				String cardNo=mer_info.getCertifNo();//证件号屏蔽
				mer_info.setCertifNo(cardNo.substring(0,3)+"****"+cardNo.substring(cardNo.length()-4));//证件号
			}
			
			String phone=mer_info.getContactPhoneNo();//手机号屏蔽
			//mer_info.setContactPhoneNo(phone.substring(0, 3)+"****"+phone.substring(phone.length()-4));//手机号
			mer_info.setContactPhoneNo(phone);
			String k2workflowid =mer_info.getK2WorkFlowId();
			mer_info.setK2WorkFlowId(k2workflowid);
			if(showName){//根据code显示名称
				mer_info.setCertifType(ConfigMerinfoUtil.getCertifType(mer_info.getCertifType()));//证件类型
				mer_info.setProvCd(ConfigMerinfoUtil.getGBProviceName(mer_info.getProvCd()));//省份
				mer_info.setCityCd(ConfigMerinfoUtil.getGBCityName(mer_info.getCityCd()));//城市
				mer_info.setAreaCd(ConfigMerinfoUtil.getGBAreaName(mer_info.getAreaCd()));//地区
				
				//查询进件人员(后期可放入与商户联查，提高页面响应速度)
				String q_sql="SELECT T.REAL_NAME FROM T_OPERATORS T WHERE T.ID=?";
				Object[] params_1={mer_info.getRecUpdOpr()};
				Object op_name=pageDao.findObj(q_sql, params_1);
				mer_info.setRecUpdOpr(String.valueOf(op_name));
			}
			 if(mer_info.getStatus().equals(MerinfoStatus.S_3.getCode())){//需要冻结原因
					String status_hql=" FROM MerinfoStatusChange T WHERE T.status='0' and T.mid=?";
					List<Object> objList=pageDao.queryAll(status_hql, param);
					List<MerinfoStatusChange> changeList=null;
					if(null!= objList && objList.size()>0){
						changeList=new ArrayList<MerinfoStatusChange>();
						for (Object object : objList) {
							MerinfoStatusChange ms=(MerinfoStatusChange)object;
							changeList.add(ms);
						}
						mer_info.setStatusChange(changeList);//冻结原因
					}
				}else if(mer_info.getStatus().equals(MerinfoStatus.S_2.getCode())){//需要注销原因
					String status_hql=" FROM MerinfoStatusChange T WHERE T.status='9' and T.mid=?";
					List<Object> objList=pageDao.queryAll(status_hql, param);
					List<MerinfoStatusChange> changeList=null;
					if(null!= objList && objList.size()>0){
						changeList=new ArrayList<MerinfoStatusChange>();
						for (Object object : objList) {
							MerinfoStatusChange ms=(MerinfoStatusChange)object;
							changeList.add(ms);
						}
						mer_info.setStatusChange(changeList);//注销原因
					}
					
				}
			
			//终端信息
			String ter_hql="from TblTermInf t where t.id.MchtCd=?";
			List<?> objList_ter=pageDao.queryAll(ter_hql, param);
			if(null!=objList_ter && objList_ter.size()>0){
				List<TblTermInf> terList=new ArrayList<TblTermInf>();
				for (Object object : objList_ter) {
					TblTermInf terminfo=(TblTermInf)object;
					if(showName){
						terminfo.setTermTp(ConfigMerinfoUtil.getPosType(terminfo.getTermTp()));//获取终端类型具体名称
					}
					//查询终端风控信息
					String risk_hql="from TblTermRiskCfg t where t.id.MchtCd=? and t.id.TermId=?";
					 Object[] param_risk={merinfoNo,terminfo.getId().getTermId()};
					List<?> objList_risk=pageDao.queryAll(risk_hql, param_risk);
					if(null!=objList_risk && objList_risk.size()>0){
						List<TblTermRiskCfg> riskList=new ArrayList<TblTermRiskCfg>();
						for (Object risk : objList_risk) {
							TblTermRiskCfg fee=(TblTermRiskCfg)risk;
							riskList.add(fee);
						}
						terminfo.setRiskCfgList(riskList); //set 终端风控信息
					}
					terList.add(terminfo);
				}
				mer_info.setTerminfoList(terList);//set终端
				TblTermRiskCfg  tmpTb= new TblTermRiskCfg();
				tmpTb.setAccpetStartTime(terList.get(0).getRiskCfgList().get(0).getAccpetStartTime());
				tmpTb.setAccpetEndTime(terList.get(0).getRiskCfgList().get(0).getAccpetEndTime());
				mer_info.setTerminfoRisk(tmpTb);//获取营业时间
			}
			//产品信息
			String del_hql="select t.prodCd,t.transCd from  TblMchtBizDeal t where t.mchtCd=?";
			List<?> objList_del=pageDao.queryAll(del_hql, param);
			if(null!=objList_del && objList_del.size()>0){
				List<TblMchtBizDeal> delList=new ArrayList<TblMchtBizDeal>();
				String[] produdctArrayStr=new String[objList_del.size()];
				int i=0;
				Iterator<?> iter=objList_del.iterator();
				while(iter.hasNext()){
					Object[] obj=(Object[])iter.next();
					TblMchtBizDeal terminfo=new TblMchtBizDeal();
					terminfo.setProdCd(String.valueOf(obj[0]));
					terminfo.setTransCd(String.valueOf(obj[1]));
					delList.add(terminfo);
					produdctArrayStr[i]=terminfo.getTransCd();
					i++;
				}
				mer_info.setBizDelList(delList); //产品集合
				mer_info.setProductStrs(produdctArrayStr);//产品
				String[] productCodeStr=queryMchtBizDealArray(merinfoNo, true,showName);
				mer_info.setProductCode(productCodeStr); //保存当前商户所选择的业务模式
			}
			
			//结算信息
			String settle_hql="from TblMchtBankAccount t where t.ownerCd=?";
			TblMchtBankAccount bankAccount=(TblMchtBankAccount)pageDao.createQueryUniqueResult(settle_hql,param );
			//String account=bankAccount.getAccount();
			//bankAccount.setAccount(account.substring(0, 4)+"****"+account.substring(account.length()-4));
			//bankAccount.setAccount(account);
			mer_info.setBankAccount(bankAccount);//SET 结算信息
			
			//手续费
			String fees_hql="select mchtCd,prodCd,bizCd,subBizCd,mchtFeePercent,mchtFeePctMax,mchtAFeePercent from TblMchtBizFee t where t.mchtCd=? order by prodCd "; 
			List<?> objList_fee=pageDao.queryAll(fees_hql, param);
			if(null!=objList_fee && objList_fee.size()>0){
				List<TblMchtBizFee> feeList=new ArrayList<TblMchtBizFee>();
				Iterator<?> iter=objList_fee.iterator();
				while(iter.hasNext()){
					Object[] obj=(Object[])iter.next();
					if(!(ConfigMerinfoUtil.ZPAY_FUNCTION_Z.equals(obj[1]) || ConfigMerinfoUtil.WPAY_FUNCTION_Z.equals(obj[1]) 
							|| ConfigMerinfoUtil.WPAY_FUNCTION_F.equals(obj[1]))){
						if(obj[3].equals(ConfigMerinfoUtil.T0_2004_FUNCTION) || 
								obj[3].equals(ConfigMerinfoUtil.T0_2005_FUNCTION)){//t0 划付手续费  跳过
								continue;
							}
							TblMchtBizFee fee=new TblMchtBizFee();
							fee.setMchtCd(String.valueOf(obj[0]));
							fee.setProdCd(String.valueOf(obj[1]));
							fee.setBizCd(String.valueOf(obj[2]));
							fee.setSubBizCd(String.valueOf(obj[3]));
							if((obj[4])!=null)
							{
								fee.setMchtFeePercent(Double.parseDouble(String.valueOf((obj[4]))));
							}
							if((obj[5])!=null)
							{
								fee.setMchtFeePctMax(Double.parseDouble(String.valueOf((obj[5]))));
							}
							if(showName){
								String name="";
								if(fee.getProdCd().equals(ConfigMerinfoUtil.T1_FUNCTION)){
									name="T1";
								}else if(fee.getProdCd().equals(ConfigMerinfoUtil.T0_FUNCTION)){
									name="T0";
								}else if(ConfigMerinfoUtil.UNIONPAY_FUNCTION.equals(fee.getProdCd())){
									name = "银联";
								}else if(ConfigMerinfoUtil.ZWPAY_FUNCTION.equals(fee.getProdCd())){
									name = "支付宝微信";
								}
								String feeCodeName = ConfigMerinfoUtil.getFeeList(String.valueOf(obj[3])); //根据code 显示手续费名称
								fee.setMchtFeeMd(name + (feeCodeName == null ? "" : feeCodeName)); 
							}
							//D0代付服务费费率
							if(ConfigMerinfoUtil.T0_2000_FUNCTION.equals(obj[3]) &&
									null != obj[6] && !(obj[6].toString().trim().equals(""))){
								fee.setMchtAFeePercent(Double.parseDouble(String.valueOf((obj[6]))));
							}
							feeList.add(fee); 
						}
					}
				mer_info.setFee(feeList); //set手续费集合
			}
			//图片信息
			String pic_hql="select t.Url,t.DocType  from TblMchtPicture t where t.MchtCd=? order by t.Pcode ASC ";
			List<?> objList_pic=pageDao.queryAll(pic_hql, param);
			if(null!=objList_pic && objList_pic.size()>0){
				List<TblMchtPicture> picList=new ArrayList<TblMchtPicture>();
				Iterator<?> iter=objList_pic.iterator();
				while(iter.hasNext()){
					Object[] obj=(Object[])iter.next();
					TblMchtPicture picture=new TblMchtPicture();
					picture.setUrl(String.valueOf(obj[0]));
					picList.add(picture); 
				}
				mer_info.setPictrueList(picList);//图片路径地址
			}
			return  mer_info;
		} catch (DaoException e) {
			 logger.error(e.getMessage(),e);
			 throw new ServiceException("--查询商户["+merinfoNo+"]详情失败",e);
		}
	}

	/**
	 * 根据商户号查询结算周期
	 * @param  mid 商户号
	 * @param  type 是否正式表
	 * @param  showName 是否显示名称
	 * */
	@Transactional(readOnly=true)
	public String[] queryMchtBizDealArray(String mid,boolean type,boolean showName) throws ServiceException {
		String tableName="TBL_EDIT_MCHT_BIZ_DEAL";
		if(type){
			tableName="TBL_MCHT_BIZ_DEAL";
		}
		String sql="SELECT DISTINCT T.PROD_CD FROM "+tableName+" T WHERE T.MCHT_CD=? ORDER BY T.PROD_CD ASC";
		List<String> productArray = new ArrayList<String>();
		try {
			Object[] params={mid};
			List<?> list=pageDao.querySqlAll(sql,params);
			Iterator<?> iter=list.iterator();
			while (iter.hasNext()) {
				Object obj=iter.next();
				if(!showName){
					productArray.add(obj.toString());
				}else{
					if(obj.toString().equals("1000")){
						productArray.add("T1");
					}else if(obj.toString().equals("1171")){
						productArray.add("T0");
					}else if(obj.toString().equals("1191")){
						productArray.add("银联扫码");
					}else if(obj.toString().equals("1391")){
						productArray.add("支付宝微信扫码");
					}
				}
			}
		} catch (DaoException e) {
			logger.error("----查询商户号["+mid+"]结算周期出错-----",e);
			throw new ServiceException("----查询商户号["+mid+"]结算周期出错-----",e);
		}
		String[] returnStr= (String[])productArray.toArray(new String[productArray.size()]);
		return returnStr;
	}

	@Override
	public List<MerinfoChangeSearchVo> queryMerinfoRejected(String id) throws ServiceException {
		List<MerinfoChangeSearchVo> merList = new ArrayList<MerinfoChangeSearchVo>();
		
		try {
			String sql = " SELECT T.MID,T.DEAL_CODE,T.REMARK,T.OPERATORS,T.DT_AUDITOR_TIME,T.STATUS FROM T_MERINFO_CHANGE T WHERE  T.STATUS='N' AND T.MID=? ORDER BY T.DT_AUDITOR_TIME ";
			Object[] params={id};
			List<?> list=sqlBaseDao.queryAll(sql,params);
			
			logger.info("根据商户号【"+id+"】查询出变更信息驳回历史记录有【"+list.size()+"】条");
			if(null!=list && list.size()>0){
				Iterator<?> iterator=list.iterator();
				while(iterator.hasNext()){
					Object[] obj = (Object[]) iterator.next();
					MerinfoChangeSearchVo mer = new MerinfoChangeSearchVo();
					
					mer.setMid(Constance.Null2EmptyTrim(obj[0]));
					mer.setDealCode(Constance.Null2EmptyTrim(obj[1]));
					mer.setRemark(Constance.Null2EmptyTrim(obj[2]));
					mer.setOperators(Constance.Null2EmptyTrim(obj[3]));
					mer.setDtAuditorTime(Constance.Null2EmptyTrim(obj[4]));
					mer.setStatus(Constance.Null2EmptyTrim(obj[5]));
					merList.add(mer);
				}
				
			}
			
		} catch (Exception e) {
			logger.debug(e.getMessage(),e);
			throw new ServiceException("查询商户【"+id+"】变更信息历史驳回记录失败");
		}
		
		return merList;
	}
}